import { apiGet, apiPost, apiPut, apiDelete } from './client'

export interface Term {
  id?: number
  name?: string
  startDate?: string
  endDate?: string
  active?: number
}

export async function listTerms(params: { name?: string } = {}) {
  return apiGet<Term[]>('/api/grades/terms', params)
}

export async function getTerm(id: number) {
  return apiGet<Term>(`/api/grades/terms/${id}`)
}

export async function createTerm(term: Term) {
  return apiPost<Term>('/api/grades/terms', term)
}

export async function updateTerm(id: number, term: Term) {
  return apiPut<Term>(`/api/grades/terms/${id}`, term)
}

export async function deleteTerm(id: number) {
  return apiDelete<string>(`/api/grades/terms/${id}`)
}